package com.xyy.yueshijia.topic;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xyy.yueshijia.R;
import com.xyy.yueshijia.topic.topicbean.HoudongBean;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/2/13.
 */

public class HuodongAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private ArrayList<HoudongBean> data;
    private Context context;
    private LayoutInflater inflater;

    public HuodongAdapter(Context context,ArrayList<HoudongBean> data) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = inflater.inflate(R.layout.huodong_item, parent, false);

        return new HuodongHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if (holder instanceof HuodongHolder){
           HuodongHolder hdholer= (HuodongHolder) holder;

            HoudongBean houdongBean = data.get(position);
            hdholer.huodongEnd.setText(houdongBean.getEnd_virtual());
            hdholer.huodongHint.setText(houdongBean.getHint_virtual());
            hdholer.huodongName.setText(houdongBean.getGoods_name());

            hdholer.huodongImage.setImageResource(R.mipmap.ic_launcher);

            String goods_image = houdongBean.getGoods_image();

            Glide.with(context).load(goods_image)
                    .placeholder(R.drawable.ic_not_logged)
                    .error(R.mipmap.ic_launcher)
                    .into( hdholer.huodongImage);
        }






    }

    @Override
    public int getItemCount() {
        return data==null?0:data.size();
    }

    class HuodongHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.huodong_image)
        ImageView huodongImage;
        @BindView(R.id.huodong_end)
        TextView huodongEnd;
        @BindView(R.id.huodong_name)
        TextView huodongName;
        @BindView(R.id.huodong_hint)
        TextView huodongHint;
        public HuodongHolder(View itemView) {
            super(itemView);

            ButterKnife.bind(this,itemView);



        }
    }
}
